//
//  RootTabBarC.m
//  FrameTestNew
//
//  Created by lanou3g on 15/5/30.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "RootTabBarC.h"
#import "GetFileSize.h"
@interface RootTabBarC ()

@end

static RootTabBarC *rootTBC;
@implementation RootTabBarC

+ (RootTabBarC*)sharedInstence{
    @synchronized(self){
        if (rootTBC ==nil) {
            rootTBC = [[RootTabBarC alloc]init];
        }
        return rootTBC;
    }
}


- (NewsViewController *)newsVC{
    if (_newsVC == nil) {
        
        _newsVC = [[NewsViewController alloc]init];
    }
    return _newsVC;
}
- (VideoViewController *)videoVC{
    if (_videoVC ==nil) {
        _videoVC = [[VideoViewController alloc]init];
        
    }
    return _videoVC;
}
- (MatchViewController *)matchVC{
    if (_matchVC ==nil) {
        _matchVC = [[MatchViewController alloc]init];
        
    }
    return _matchVC;
}

- (RankingViewController*)rankVC{
    if (_rankVC ==nil) {
        _rankVC = [[RankingViewController alloc]init];
    }
    return _rankVC;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    

    [self setupViewControllers];
    [self setupSegment];
    [self setupDrawer];

    
    self.tabBar.tintColor = [UIColor whiteColor];
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 49)];
    view.backgroundColor = [UIColor colorWithRed:235/255.0 green:234/255.0 blue:235/255.0 alpha:1.0];
    
    [self.tabBar insertSubview:view atIndex:0];
    
}


- (void)setupSegment{
    
    NSArray *array =@[@"CBA",@"中超",@"欧冠",@"意甲"];
    self.segmentControll = [[UISegmentedControl alloc]initWithItems:array];
    self.segmentControll.selectedSegmentIndex =0;
    
    [self.segmentControll addTarget:self action:@selector(segmentValueChange:) forControlEvents:UIControlEventValueChanged];
    
//设置segment :去掉边框以及设置选中和未选中的字体
    self.segmentControll.tintColor = [UIColor clearColor];
    NSDictionary* selectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],
NSForegroundColorAttributeName: [UIColor whiteColor]};
    [self.segmentControll setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];//设置文字属性
    NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],
                                               NSForegroundColorAttributeName: [UIColor colorWithRed:72/255.0 green:105/255.0 blue:141/255.0 alpha:1.0]};
    [self.segmentControll setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];
//////////////////////////////////////////////////colorWithRed:115/255.0 green:151/255.0 blue:190/255.0 alpha:1.0
    
    
    self.navigationItem.titleView = self.segmentControll;
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(excute:) name:scrollSendNotification object:nil];
    
    
    
}

#pragma ---segmentControll的观察者---

- (void)excute:(NSNotification*)notification{
    
    NSNumber *number = (NSNumber *)notification.object;
    self.segmentControll.selectedSegmentIndex = [number integerValue];
    
}


- (void)segmentValueChange:(UISegmentedControl*)segment{
   
    [[NSNotificationCenter defaultCenter] postNotificationName:segmentSendNotification object:[NSNumber numberWithInteger:segment.selectedSegmentIndex]];
    
}





- (void)setupViewControllers{
    
    
    self.newsVC.title = @"新闻";
    self.newsVC.tabBarItem.tag = 101;
   
    self.newsVC.tabBarItem.image = [[UIImage imageNamed:@"whiteNews"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.newsVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"news"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    
    
    [self.newsVC.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Bold" size:10.5f],NSForegroundColorAttributeName:[UIColor colorWithRed:133/255.0 green:133/255.0 blue:133/255.0 alpha:1.0]} forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Bold" size:10.5f],NSForegroundColorAttributeName:[UIColor colorWithRed:40/255.0 green:65/255.0 blue:92/255.0 alpha:1.0]} forState:UIControlStateSelected];
    self.newsVC.view.backgroundColor = [UIColor whiteColor];
    
    self.matchVC.title = @"比赛";
    self.matchVC.tabBarItem.tag = 102;
    self.matchVC.view.backgroundColor = [UIColor greenColor];
    self.matchVC.tabBarItem.image = [[UIImage imageNamed:@"whiteMatch"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.matchVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"match"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [self.matchVC.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Bold" size:10.5f],NSForegroundColorAttributeName:[UIColor colorWithRed:133/255.0 green:133/255.0 blue:133/255.0 alpha:1.0]} forState:UIControlStateNormal];
    [self.matchVC.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Bold" size:10.5f],NSForegroundColorAttributeName:[UIColor colorWithRed:40/255.0 green:65/255.0 blue:92/255.0 alpha:1.0]} forState:UIControlStateSelected];
    
    self.videoVC.view.backgroundColor = [UIColor whiteColor];
    self.videoVC.title = @"视频";
    self.videoVC.tabBarItem.tag = 103;
    self.videoVC.tabBarItem.image = [[UIImage imageNamed:@"whiteVideo"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.videoVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"video"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [self.videoVC.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Bold" size:10.5f],NSForegroundColorAttributeName:[UIColor colorWithRed:133/255.0 green:133/255.0 blue:133/255.0 alpha:1.0]} forState:UIControlStateNormal];
    [self.videoVC.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Bold" size:10.5f],NSForegroundColorAttributeName:[UIColor colorWithRed:40/255.0 green:65/255.0 blue:92/255.0 alpha:1.0]} forState:UIControlStateSelected];
    
    self.rankVC.view.backgroundColor = [UIColor whiteColor];
    self.rankVC.title = @"排名";
    self.rankVC.tabBarItem.tag = 104;
    self.rankVC.tabBarItem.image = [[UIImage imageNamed:@"whiteRank"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.rankVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"Rank"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    
    self.viewControllers = @[self.newsVC,self.matchVC,self.videoVC,self.rankVC];
    [self.rankVC.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Bold" size:10.5f],NSForegroundColorAttributeName:[UIColor colorWithRed:133/255.0 green:133/255.0 blue:133/255.0 alpha:1.0]} forState:UIControlStateNormal];
    [self.rankVC.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Bold" size:10.5f],NSForegroundColorAttributeName:[UIColor colorWithRed:40/255.0 green:65/255.0 blue:92/255.0 alpha:1.0]} forState:UIControlStateSelected];
    
}


//抽屉----
- (void)setupDrawer{
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 25, CGRectGetHeight(self.view.frame)-113)];
    UIPanGestureRecognizer *regcognizer=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan)];
    [view addGestureRecognizer:regcognizer];
    [self.view addSubview:view];

    
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setImage:[UIImage imageNamed:@"More"] forState:(UIControlStateNormal)];
    button.imageView.tintColor = [UIColor whiteColor];
    button.frame = CGRectMake(0, 0, 24, 24);
    button.tintColor = [UIColor whiteColor];
    [button addTarget:self action:@selector(presentDrawer) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * barButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = barButtonItem;


}
int n=0;
- (void)handlePan
{
    n=n+1;
   
    if (n==8) {
        [self presentDrawer];
        n=0;
    }
}
- (void)presentDrawer{
    [self.sideMenuViewController presentLeftMenuViewController];

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
